<link rel="stylesheet" type="text/css"
    href="/static/yui_3.6.0/yui/build/cssreset-context/cssreset-context-min.css">
<link rel="stylesheet" type="text/css" href="/modules/oeditor/buttonbar.css">
<script
    src="/static/yui_3.6.0/yui/build/yui/yui.js"></script>
<link rel="stylesheet" type="text/css"
    href="/static/inputex-3.1.0/src/inputex/assets/skins/sam/inputex.css">
<link rel="stylesheet" type="text/css" href="/modules/oeditor/resources/butterbar.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/modules/oeditor/resources/butterbar.js" type='text/javascript'></script>
<script src="/modules/oeditor/resources/popup.js" type='text/javascript'></script>
<script
    src="/static/inputex-3.1.0/src/loader.js" type='text/javascript'></script>

<!-- import CodeMirror -->
<script src="/static/codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="/static/codemirror/lib/codemirror.css">
<script src="/static/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="/static/codemirror/mode/xml/xml.js"></script>
<script src="/static/codemirror/mode/javascript/javascript.js"></script>
<script src="/static/codemirror/mode/css/css.js"></script>
<script src="/static/codemirror/keymap/sublime.js"></script>
<script src="/static/codemirror/addon/mode/loadmode.js"></script>
<link rel="stylesheet" href="/static/codemirror/addon/fold/foldgutter.css">
<script src="/static/codemirror/addon/fold/foldcode.js"></script>
<script src="/static/codemirror/addon/fold/foldgutter.js"></script>
<script src="/static/codemirror/addon/fold/brace-fold.js"></script>
<script src="/static/codemirror/addon/fold/xml-fold.js"></script>
<script src="/static/codemirror/addon/fold/markdown-fold.js"></script>
<script src="/static/codemirror/addon/fold/comment-fold.js"></script>
<link rel="stylesheet" href="/static/codemirror/addon/dialog/dialog.css">
<script src="/static/codemirror/addon/dialog/dialog.js"></script>
<script src="/static/codemirror/addon/search/searchcursor.js"></script>
<script src="/static/codemirror/addon/search/search.js"></script>

<!-- import extension libraries. -->
{% for url in extra_script_tag_urls %}
  <script src='{{ url }}'></script>
{% endfor %}

<link rel="stylesheet" type="text/css"
    href="/modules/oeditor/resources/oeditor.css"/>
<style>
  {% for file in extra_css_files %}
    {% include file %}
  {% endfor %}
</style>

<div id='oeditor-container'>
  <div class='gcb-butterbar-container'>
    <div class='gcb-butterbar' id='gcb-butterbar-top' style='top:-45px'>
      <p id='gcb-butterbar-message'></p>
      <a id='gcb-butterbar-close'>X</a>
    </div>
  </div>
  <div style='width: 100%;' align='center' class='yui3-skin-sam yui-skin-sam'>
    <div class='form' id='formContainer'></div>
  </div>
</div>
<div id='modal-editor' class='hidden'>
  <div class='background'></div>
</div>

<script type='text/javascript'>
  (function() {
    //keep all our global objects here
    var cb_global = {};

    // various URL's needed by the form
    cb_global.get_url = '{{ get_url|js_string }}';
    cb_global.save_url = '{{ save_url|js_string }}';
    cb_global.save_args = JSON.parse("{{ save_args|js_string }}");
    cb_global.exit_button_caption = '{{ exit_button_caption|js_string }}';
    cb_global.exit_url = '{{ exit_url|js_string }}';
    cb_global.save_method = '{{ save_method|js_string }}';
    cb_global.auto_return = {% if auto_return %}true{% else %}false{% endif %};
    cb_global.bundle_lib_files = {% if bundle_lib_files %}true{% else %}false{% endif %};

    // If this value is '', deletions are not allowed
    cb_global.delete_url = '{{ delete_url|js_string }}';
    cb_global.delete_method = '{{ delete_method|js_string }}';

    // button captions
    cb_global.delete_button_caption = '{{ delete_button_caption|js_string }}'
    cb_global.save_button_caption = '{{ save_button_caption|js_string }}'
    cb_global.rte_tag_data = JSON.parse("{{ rte_tag_data|js_string }}");

    cb_global.required_modules = [{% for module in required_modules %}
        '{{ module|js_string }}'{% if not loop.last %},{% endif %}{% endfor %}];
    cb_global.schema = JSON.parse("{{ schema|js_string }}");
    cb_global.delete_message = '{{ delete_message|js_string }}';
    cb_global.preview_xsrf_token = '{{ preview_xsrf_token | js_string }}';
    cb_global.editor_prefs = JSON.parse('{{ editor_prefs | js_string }}');
    cb_global.load_schema_with_annotations = function(schema) {
      {% for annotation in schema_annotations %}
        schema.root{% for element in annotation[0] %}['{{element|js_string}}']{% endfor %}
          = JSON.parse("{{ annotation[1]|js_string }}")
      {% endfor %}
    }
    cb_global.onFormLoad = function(Y) {
      {% for file in extra_js_files %}
        {% include file %}
      {% endfor %}
    };

    {% include 'oeditor.js' %}
    {% include 'rte.js' %}
    {% include 'code.js' %}
    {% include 'uneditable.js' %}

    window.addEventListener('load', function(){
      onPageLoad(cb_global);
    });
  })();
</script>
